package com.lx.testelk;

import com.lx.testelk.Enums.ELKMsgCodeEnums;
import com.lx.testelk.Enums.ELKMsgTypeEnums;
import com.lx.testelk.aspect.WebLogAspect;
import com.lx.testelk.entity.ELKMessage;
import com.lx.testelk.util.MapperUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.apache.skywalking.apm.toolkit.trace.TraceContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@Slf4j
@SpringBootApplication
public class TestElkApplication {

    private static final Logger LOGGER = LoggerFactory.getLogger(WebLogAspect.class);




    @Trace
    @SneakyThrows
    public static void main(String[] args) {

        SpringApplication.run(TestElkApplication.class, args);
        log.info("------------启动成功-------------------");

        String traceId = TraceContext.traceId();
        System.out.println("----traceId是:"+traceId+"----");

        ELKMessage msg1 = new ELKMessage().builder()
                .Type(ELKMsgTypeEnums.ERROR.getValue())
                .Errorcode(ELKMsgCodeEnums.one_ERROR.getValue())
                .msg("日志信息测试")
                .TraceId(traceId)
                .build();

      ELKMessage msg2 = new ELKMessage().builder()
                .Type(ELKMsgTypeEnums.ERROR.getValue())
                .Errorcode(ELKMsgCodeEnums.two_ERROR.getValue())
                .msg("日志信息测试")
                .TraceId(traceId)
                .build();

      ELKMessage msg3 = new ELKMessage().builder()
                .Type(ELKMsgTypeEnums.ERROR.getValue())
                .Errorcode(ELKMsgCodeEnums.three_ERROR.getValue())
                .msg("日志信息测试")
                .TraceId(traceId)
                .build();

      ELKMessage msg4 = new ELKMessage().builder()
                .Type(ELKMsgTypeEnums.SUCCESS.getValue())
                .Errorcode(ELKMsgCodeEnums.SUCCESS.getValue())
                .msg("日志信息测试")
                .TraceId(traceId)
                .build();

        String json1 = MapperUtils.obj2json(msg1);
        String json2 = MapperUtils.obj2json(msg2);
        String json3 = MapperUtils.obj2json(msg3);
        String json4 = MapperUtils.obj2json(msg4);
        System.out.println(json1);



        while(true){
            //        LOGGER.info(json1);
            LOGGER.error(json1);

            System.out.println(json2);
//        LOGGER.info(json2);
            LOGGER.error(json2);

            System.out.println(json3);
//        LOGGER.info(json3);
            LOGGER.error(json3);


            System.out.println(json4);
            LOGGER.info(json4);
//        LOGGER.error(json4);

            Thread.sleep(1000);
        }

    }

}
